package com.example.crm.service.Imple;

import com.example.crm.mapper.CourseOrderMapper;
import com.example.crm.model.CourseCategory;
import com.example.crm.model.CourseOrder;
import com.example.crm.model.PageResult;
import com.example.crm.model.UserInfo;
import com.example.crm.service.interfase.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseOrderServiceImpl implements ICourseOrderService {

    @Autowired
    CourseOrderMapper orderMapper;
    public PageResult<CourseOrder> findPageResult(CourseOrder courseOrder, int page, int pageSize) {
PageResult<CourseOrder>result=new PageResult<CourseOrder>();
result.setCode(0);
        Map<String,Object>params = new HashMap<String,Object>();
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);
//        获取总记录
        int totalCount = orderMapper.findCountByMap(params);
        result.setCount(totalCount);
//        获取查询数据
        List<CourseOrder> list = orderMapper.findListByMap(params);


        result.setData((list));
        return result;
    }

    @Override
    public List<CourseCategory> findAllList() {
        return orderMapper.findAllList();
    }

    @Override
    public UserInfo findUserByname(String username) {
        return orderMapper.findUseByName(username);
    }
}
